package com.example.kafka;

import com.example.kafka.integration.Topic;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.stream.annotation.EnableBinding;
import org.springframework.messaging.support.MessageBuilder;

@Slf4j
@SpringBootApplication
@EnableBinding(Topic.class)
public class RabbitmqServiceApplication implements ApplicationRunner {

	@Autowired
	private Topic topic;

	public static void main(String[] args) {
		SpringApplication.run(RabbitmqServiceApplication.class, args);
	}

	@Override
	public void run(ApplicationArguments args) throws Exception {
		boolean result = topic.sender().send(MessageBuilder.withPayload(System.currentTimeMillis()).build());
		if (result) {
			log.info("消息发送成功");
		} else {
			log.info("消息发送失败");
		}
	}
}
